﻿Function Get-IISLogLocation {
<#
.SYNOPSIS
    This function can be ran against a server or multiple servers to locate
    the log file location for each web site configured in IIS.
.DESCRIPTION
    This function can be ran against a server or multiple servers to locate
    the log file location for each web site configured in IIS.
.PARAMETER computer
    Name of computer to query log file location.
.NOTES
    Name: Get-IISLogLocation
    Author: Boe Prox
    DateCreated: 11Aug2010  

.LINK   

http://boeprox.wordpress.com

.EXAMPLE
Get-IISLogLocation -computer 'server1' 

Description
-----------
This command will list the IIS log location for each website configured on 'Server1' 

#>
[cmdletbinding(
    SupportsShouldProcess = $True,
    DefaultParameterSetName = 'computer',
    ConfirmImpact = 'low'
)]
param(
    [Parameter(
        Mandatory = $False,
        ParameterSetName = 'computer',
        ValueFromPipeline = $True)]
        [string[]]$computer
)
Begin {
    $report = @()
    }
Process {
    ForEach ($c in $Computer) {
            Write-Verbose "Checking connection on $($c)"

            If (Test-Connection -comp $c -count 1) { 

                Write-Verbose "Making IIS connection to $($c)"
                $sites = [adsi]"IIS://$c/W3SVC"
                $children = $sites.children
                ForEach ($child in $children) {
                    Write-Verbose "Checking $child.servercomment"
                    If ($child.KeyType -eq "IIsWebServer") {
                        Write-Verbose "Found site"
                        $temp = "" | Select Server, WebSite, LogLocation, Name
                        $temp.Server = $c
                        $temp.WebSite = $child.ServerComment
                        $temp.LogLocation = $child.LogFileDirectory
						$temp.Name = $child.Name
                        $report += $temp
                        }
                    }
            }
        }
    }
End {
    $report
    }
}